<?php

namespace app\user\controller;

use app\user\controller\Base;

class Auth extends Base
{
    //需验证方法集
    protected $is_check_login = [''];

    //初始化
    public function _initialize()
    {
        $IndexPage = input('IndexPage') == null ? 'index' : input('IndexPage');
        //判断是否登录，执行方法是否需要验证登录
        if (!$this->isLogin() && (!in_array($IndexPage, $this->is_check_login) || $this->is_check_login[0] == "*")) {
            return $this->error('请先登录!', "/user/login");
        }
    }

    //判断登录状态
    public function isLogin()
    {
        return session('?userlycmsauth');
    }

    // 更新用户登录信息
    public function upUserInfo($data)
    {
        $info['user_login_time'] = time();
        $info['user_login_ip'] = request()->ip();
        $info['user_count']  = $data['user_count'] + 1;
        $info['user_last_login_ip'] = $data['user_login_ip'];
        $info['user_last_login_time'] = $data['user_login_time'];
        $res = db('v1_user')->where("user_name", $data['user_name'])->update($info);
        return $res;
    }
}
